/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.spring.boot.controller;

import cn.hutool.poi.excel.ExcelUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.spring.boot.entity.ChinaCity;
import com.spring.boot.response.Result;
import com.spring.boot.service.ChinaCityService;
import lombok.RequiredArgsConstructor;
//import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;


/**
 * 全国地级市疫情
 *
 * @author fl
 * @date 2022-05-15 19:39:16
 */
@RestController
@RequiredArgsConstructor
@PreAuthorize("hasAnyAuthority('ROLE_dataChinaCity')")
@RequestMapping("/datachinacity" )

public class DataChinaCityController {

    private final ChinaCityService dataChinaCityService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param dataChinaCity 全国地级市疫情
     * @return
     */
//    @Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/page" )
//    @PreAuthorize("@pms.hasPermission('demo_datachinacity_get')" )
    public Result getDataChinaCityPage(Page page, ChinaCity dataChinaCity) {
        return Result.OK(dataChinaCityService.page(page, Wrappers.query(dataChinaCity)));
    }


    /**
     * 通过id查询全国地级市疫情
     * @param id id
     * @return R
     */
//    @Operation(summary = "通过id查询", description = "通过id查询")
    @GetMapping("/{id}" )
//    @PreAuthorize("@pms.hasPermission('demo_datachinacity_get')" )
    public Result getById(@PathVariable("id" ) Integer id) {
        return Result.OK(dataChinaCityService.getChinaCityById(id));
    }

    /**
     * 新增全国地级市疫情
     * @param dataChinaCity 全国地级市疫情
     * @return R
     */
//    @Operation(summary = "新增全国地级市疫情", description = "新增全国地级市疫情")
//    @SysLog("新增全国地级市疫情" )
    @PostMapping
//    @PreAuthorize("@pms.hasPermission('demo_datachinacity_add')" )
    public Result save(@RequestBody ChinaCity dataChinaCity) {
        return Result.OK(dataChinaCityService.save(dataChinaCity));
    }

    /**
     * 修改全国地级市疫情
     * @param dataChinaCity 全国地级市疫情
     * @return R
     */
//    @Operation(summary = "修改全国地级市疫情", description = "修改全国地级市疫情")
//    @SysLog("修改全国地级市疫情" )
    @PutMapping
//    @PreAuthorize("@pms.hasPermission('demo_datachinacity_edit')" )
    public Result updateById(@RequestBody ChinaCity dataChinaCity) {
        return Result.OK(dataChinaCityService.updateChinaCityById(dataChinaCity));
    }

    /**
     * 通过id删除全国地级市疫情
     * @param id id
     * @return R
     */
//    @Operation(summary = "通过id删除全国地级市疫情", description = "通过id删除全国地级市疫情")
//    @SysLog("通过id删除全国地级市疫情" )
    @DeleteMapping("/{id}" )
//    @PreAuthorize("@pms.hasPermission('demo_datachinacity_del')" )
    public Result removeById(@PathVariable Integer id) {
        return Result.OK(dataChinaCityService.removeChinaCityById(id));
    }

    /**
     * 导入疫情数据
     * @param file excel文件
//     * @param bindingResult 错误信息列表
     * @return R
     */
    @PostMapping("/import")
//    @PreAuthorize("@pms.hasPermission('sys_user_import_export')")
    public Result importUser(@RequestParam("file") MultipartFile file) throws IOException {
        return dataChinaCityService.importData(file);
    }

}
